#ifndef BUFFER_H_
#define BUFFER_H_

#ifndef NOODIRECT
#define ODIRECT O_DIRECT
#else
#define ODIRECT 0
#endif

#define BUFFER_SIZE (100 * (size_t)getpagesize())

#include <pthread.h>
#include <semaphore.h>
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <iostream>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <assert.h>

class Buffer {

protected:
	pthread_t thread;

	sem_t* full;
	sem_t* empty;

	char* buffer0;
	char* buffer1;
	char* buffer2;

	unsigned int currentBuffer;
	unsigned int bufferIndex;

	int file;

	bool isInitialized;

	bool isFinished;

	//start thread
	virtual int startThread(pthread_t* thread, Buffer* arg);

	static void* fct(void* arg);

public:
	Buffer();
	~Buffer();

	//functionality of thread
	virtual bool run();

};

#endif
